home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS09.ADF
/
AmigaBasicProgs
/
HuePalette
(
.txt
)
< prev
next >
Wrap
AmigaBASIC Source Code
|
1986-05-22
|
3KB
|
149 lines
'
' HSI to RGB Conversion Tool
' By Stephen R. Pietrowicz
'
SCREEN 1,640,200,4,2
WINDOW 2,"HSI to RGB Conversion Tool By Stephen R. Pietrowicz",,0,1
DEF FN a(n) = 2*I*((S*n)+0.5)
DEF FN b(n) = 0.5+(S*n)+2*(I-0.5)*(0.5-(S*n))
GOSUB Init
MouseInput:
GOSUB PrintVals
'
' Wait for left mouse button to be clicked
'
WHILE MOUSE(0) = 0 : WEND
x = MOUSE(3):y = MOUSE(4)
'
' Check for box boundries
'
IF (y < 100) OR (y > 180) THEN MouseInput
IF (x < 50) OR (x > 550) THEN MouseInput
'
' Hue Selected
'
IF (y <= 130) THEN
IF (x >= 120) AND (x <= 480) THEN
Hue = (x - 120)
H = Hue/360
COLOR 0
LINE (hx,102)-(hx,128)
COLOR 1
LINE (x,102)-(x,128)
hx = x
END IF
'
' Saturation Selected
'
ELSEIF (y >= 150) THEN
IF (x <= 150) THEN
S = (x - 50)/100
COLOR 0
LINE (sx,152)-(sx,178)
COLOR 1
LINE (x,152)-(x,178)
sx = x
'
' Intensity Selected
'
ELSEIF (x >= 450) THEN
I = (x - 450)/100
COLOR 0
LINE (ix,152)-(ix,178)
COLOR 1
LINE (x,152)-(x,178)
ix = x
END IF
END IF
GOSUB Convert
GOTO MouseInput
Init:
CLS
COLOR 3
LINE(118,100)-(482,130),,b
LINE(48,150)-(152,180),,b
LINE(448,150)-(552,180),,b
hx = 120: sx = 50: ix = 450
COLOR 1
LINE (hx,102)-(hx,128)
LINE (sx,152)-(sx,178)
LINE (ix,152)-(ix,178)
COLOR 2
LINE (50,25)-(550,75),,bf
COLOR 1
LINE (50,25)-(550,75),,b
r = 0: g = 0: b = 0 : S = 0 : I = 0
RETURN
'
' Change given HSI coordinates to RGB
'
Convert:
IF H < 0.16 THEN
Red = 1
Green = H*6
Blue = 0
ELSEIF H < 0.33 THEN
Red = 2 - H*6
Green = 1
Blue = 0
ELSEIF H < 0.5 THEN
Red = 0
Green = 1
Blue = 6*H - 2
ELSEIF H < 0.66 THEN
Red = 0
Green = 4 - H*6
Blue = 1
ELSEIF H < 0.83 THEN
Red = H*6 - 4
Green = 0
Blue = 1
ELSE
Red = 1
Green = 0
Blue = 6 - 6*H
END IF
Red = Red - 0.5
Green = Green - 0.5
Blue = Blue - 0.5
IF (I <= 0.5) THEN
Red = FN a(Red)
Green = FN a(Green)
Blue = FN a(Blue)
ELSE
Red = FN b(Red)
Green = FN b(Green)
Blue = FN b(Blue)
END IF
IF Red > 1 THEN Red = 1
IF Green > 1 THEN Red = 1
IF Blue > 1 THEN Red = 1
IF Red < 0 THEN Red = 0
IF Green < 0 THEN Green = 0
IF Blue < 0 THEN Blue = 0
PALETTE 2,Red,Green,Blue
RETURN
PrintVals:
COLOR 3
LOCATE 2,22
PRINT USING "Red = #.## ";Red;
PRINT USING "Green = #.## ";Green;
PRINT USING "Blue = #.##";Blue
LOCATE 12, 34
PRINT USING "Hue = ###";Hue
LOCATE 18, 5
PRINT USING "Saturation = #.##";S
LOCATE 18, 55
PRINT USING "Intensity = #.##";I
COLOR 2
RETURN